using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MicroMsg.Storage
{
	public class SnsInfoStorage : StorageTable<SnsInfo, int>
	{
		public SnsInfoStorage() : base((SnsInfo sns) => sns.nLocalID)
		{
		}
		public bool updateListByObjectID(List<SnsInfo> snsList)
		{
			return base.updateList<string>(snsList, (SnsInfo sns) => sns.strObjectID);
		}
		public SnsInfo getByObjectID(string strObjectID)
		{
			return base.method_2((SnsInfo sns) => sns.strObjectID == strObjectID);
		}
		public Dictionary<string, int> getCheckSum(List<string> objectIDList)
		{
			if (objectIDList != null && objectIDList.get_Count() > 0 && base.isReady())
			{
				Dictionary<string, int> result;
				try
				{
					var queryable = Queryable.Select(Queryable.Where<SnsInfo>(this.tableR, (SnsInfo s) => objectIDList.Contains(s.strObjectID)), (SnsInfo s) => new
					{
						gparam_0 = s.strObjectID,
						checkSum = s.nCheckSum
					});
					Dictionary<string, int> dictionary = new Dictionary<string, int>();
					using (var enumerator = queryable.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							var current = enumerator.get_Current();
							if (!dictionary.ContainsKey(current.Prop_0))
							{
								dictionary.set_Item(current.Prop_0, current.checkSum);
							}
						}
					}
					result = dictionary;
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "getCheckSumList  exception" + ex);
					result = null;
				}
				return result;
			}
			return null;
		}
		public Dictionary<ulong, int> getObjectStyle(List<ulong> objectIDList)
		{
			if (objectIDList != null && objectIDList.get_Count() > 0 && base.isReady())
			{
				Dictionary<ulong, int> result;
				try
				{
					var queryable = Queryable.Select(this.tableR, (SnsInfo s) => new
					{
						strId = s.strObjectID,
						nStyle = s.nObjectStyle
					});
					Dictionary<ulong, int> dictionary = new Dictionary<ulong, int>();
					using (var enumerator = queryable.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							var current = enumerator.get_Current();
							ulong num = SnsInfo.toID(current.strId);
							if (objectIDList.Contains(num))
							{
								dictionary.set_Item(num, current.nStyle);
							}
						}
					}
					result = dictionary;
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "getCheckSumList  exception" + ex);
					result = null;
				}
				return result;
			}
			return null;
		}
		public List<SnsInfo> getList(List<string> objectIDList)
		{
			if (objectIDList != null && objectIDList.get_Count() > 0 && base.isReady())
			{
				List<SnsInfo> result;
				try
				{
					IOrderedQueryable<SnsInfo> orderedQueryable = Queryable.OrderByDescending<SnsInfo, string>(Queryable.Where<SnsInfo>(this.tableR, (SnsInfo s) => objectIDList.Contains(s.strObjectID)), (SnsInfo s) => s.strObjectID);
					result = Enumerable.ToList<SnsInfo>(orderedQueryable);
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "getList  exception" + ex);
					result = null;
				}
				return result;
			}
			return null;
		}
		public List<SnsInfo> getList(int start, int int_0)
		{
			if (!base.isReady())
			{
				return null;
			}
			List<SnsInfo> result;
			try
			{
				IQueryable<SnsInfo> queryable = Queryable.Take<SnsInfo>(Queryable.Skip<SnsInfo>(Queryable.OrderByDescending<SnsInfo, string>(this.tableR, (SnsInfo s) => s.strObjectID), start), int_0);
				result = Enumerable.ToList<SnsInfo>(queryable);
			}
			catch (Exception ex)
			{
				Log.smethod_1("storage", "getList exception" + ex);
				result = null;
			}
			return result;
		}
		public List<ulong> getObjectID()
		{
			if (!base.isReady())
			{
				return null;
			}
			List<ulong> result;
			try
			{
				List<string> list = Enumerable.ToList<string>(Queryable.Select<SnsInfo, string>(this.tableR, (SnsInfo s) => s.strObjectID));
				List<ulong> list2 = new List<ulong>();
				using (List<string>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string current = enumerator.get_Current();
						list2.Add(SnsInfo.toID(current));
					}
				}
				result = list2;
			}
			catch (Exception ex)
			{
				Log.smethod_1("storage", "getObjectIDList  exception" + ex);
				result = null;
			}
			return result;
		}
		public bool delByObjectID(string strObjectID)
		{
			return base.method_6((SnsInfo sns) => sns.strObjectID == strObjectID);
		}
		public bool delList(List<ulong> ObjectIDList)
		{
			if (ObjectIDList != null && ObjectIDList.get_Count() > 0)
			{
				List<string> strObjectIDList = Enumerable.ToList<string>(Enumerable.Select<ulong, string>(ObjectIDList, (ulong ulong_0) => SnsInfo.toStrID(ulong_0)));
				return base.method_6((SnsInfo sns) => strObjectIDList.Contains(sns.strObjectID));
			}
			return true;
		}
		public bool updateByObjectID(SnsInfo item)
		{
			return base.update(item, (SnsInfo s) => s.strObjectID == item.strObjectID);
		}
		public override void notify(int operation, SnsInfo item)
		{
			EventCenter.postCombineEvent(EventConst.ON_STORAGE_SNSINFO_ADD + operation, item);
		}
		public void test()
		{
			base.clearAll();
			base.method_3(new SnsInfo
			{
				strObjectID = "111",
				strUserName = "1"
			});
			base.method_3(new SnsInfo
			{
				strObjectID = "222",
				strUserName = "222"
			});
			base.method_3(new SnsInfo
			{
				strObjectID = "222",
				strUserName = "22"
			});
			base.method_3(new SnsInfo
			{
				strObjectID = "222",
				strUserName = "2"
			});
			base.method_3(new SnsInfo
			{
				strObjectID = "333",
				strUserName = "3"
			});
			base.method_3(new SnsInfo
			{
				strObjectID = "444",
				strUserName = "4"
			});
			base.method_3(new SnsInfo
			{
				strUserName = "5"
			});
			SnsInfo snsInfo = new SnsInfo
			{
				strObjectID = "222",
				strUserName = "22222"
			};
			SnsInfo snsInfo2 = new SnsInfo
			{
				strObjectID = "111",
				strUserName = "11"
			};
			List<SnsInfo> list = new List<SnsInfo>();
			list.Add(snsInfo);
			list.Add(snsInfo2);
			base.updateList<string>(list, (SnsInfo s) => s.strObjectID);
			this.dumpTable();
		}
	}
}
